package com.example.newsapp.model;

import android.util.Log;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class Comment {
    private Long id;
    private Long userId;
    private String userName;
    private String userAvatar;
    private String content;
    private long timestamp;
    private Long parentId; // 父评论ID，如果是一级评论则为null
    private Long replyToUserId;    // 回复的用户ID（谁发的那条评论）
    private String replyToUserName;  // 回复的用户昵称
    private List<Comment> replies; // 回复列表

    public Comment() {
        this.replies = new ArrayList<>();
    }

    //一级评论
    public Comment(Long id, Long userId, String userName, String userAvatar, String content,long timestamp) {
        this.id = id;
        this.userId = userId;
        this.userName = userName;
        this.userAvatar = userAvatar;
        this.content = content;
        this.timestamp = timestamp;
        this.replies = new ArrayList<>();
    }

    //回复
    public Comment(Long id, Long userId, String userName, String userAvatar, String content,Long parentId, Long replyToUserId,String replyToUserName, long timestamp) {
        this.id = id;
        this.userId = userId;
        this.userName = userName;
        this.userAvatar = userAvatar;
        this.content = content;
        this.timestamp = timestamp;
        this.parentId = parentId;
        this.replyToUserId = replyToUserId;
        this.replyToUserName = replyToUserName;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserAvatar() {
        return userAvatar;
    }

    public void setUserAvatar(String userAvatar) {
        this.userAvatar = userAvatar;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getReplyToUserId() {
        return replyToUserId;
    }

    public void setReplyToUserId(Long replyToUserId) {
        this.replyToUserId = replyToUserId;
    }

    public String getReplyToUserName() {
        return replyToUserName;
    }

    public void setReplyToUserName(String replyToUserName) {
        this.replyToUserName = replyToUserName;
    }

    public List<Comment> getReplies() {
        return replies;
    }

    public void setReplies(List<Comment> replies) {
        this.replies = replies;
    }

    public void addReply(Comment reply) {
        if (replies == null) {
            replies = new ArrayList<>();
        }
        replies.add(reply);
    }

    public boolean isReply() {
        return parentId != null;
    }
}